<?php
namespace Shared\Extensions\Twig;

/**
 * Description of LRCSupport
 *
 * @author nofear
 */
class LRCSupport extends \Twig_Extension {
    
    private $LRCSupport;
    private $EntityManager;
    
    public function __construct() {
        $this->EntityManager = \Shared\Application::instance()->getEntityManager();
        $this->LRCSupport = \Shared\Application::instance()->getLRCSupport();
    }
    
    public function getGlobals() {
        return array(
            'LRCSupport' => $this
        );
    }
    
    public function label($key, $Language = null) {
        $Label = $this->EntityManager->getRepository('Shared\Main\Label')->findOneBySlug($key);
        
        if (!$Label) {
            throw new \Exception('Label ' . $key . ' not found!');
        }
        
        return $this->LRCSupport->getManager($Label)->get('value', $Language);
    }
    
    public function get($Object, $property, $Language = null) {
        return $this->LRCSupport->getManager($Object)->get($property, $Language);
    }
    
    public function getName() {
        return 'LRCSupport';
    }
}
